<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Index extends CI_Model {
	
	public function logado(){
		if ($this->session->userdata('grupo_usuario') == NULL) {
			return FALSE;
		} else {
			return $this->session->userdata('grupo_usuario');
		}
	}
	
	public function montarPagina($sView, $aData = NULL){
		$aData['_head'] = array(
				'titulo' => 'qrMenu',
				'stylesheet' => array (
						base_url() . CSS . 'reset.css',
						base_url() . CSS . 'layout.css',
						base_url() . CSS . 'style.css',
						base_url() . CSS . 'nav.css',
						base_url() . CSS . 'icones.css',
						base_url() . CSS . 'jquery.fancybox/jquery.fancybox.css',
						base_url() . CSS . 'jquery.parsley/jquery.parsley.css'
				),
				'javascript' => array (
						base_url() . JS . 'jquery-2.0.0.min.js',
						base_url() . JS . 'nav.js',
						base_url() . JS . strstr($sView, '/', true) . '.js',
						base_url() . JS . 'jquery.fancybox/jquery.fancybox.min.js',
						base_url() . JS . 'jquery.maskedInput/jquery.maskedInput.min.js',
						base_url() . JS . 'jquery.parsley/jquery.parsley.min.js'
				)
		);
		
		$aData['_footer'] = array(
				'versao' => 'qrMenu - v0.1.0'
		);

		if($this->logado() == FALSE) {
			$this->montarLayout('usuario/login_view', $aData);
			
		} else if($this->logado()) {

			switch ($this->logado()) {
				
				case 'mesa':
					
					break;
				
				case 'administrador':
					
					array_push($aData['_head']['stylesheet'], base_url() . CSS . 'jquery.dataTables/jquery.dataTables.css');
					array_push($aData['_head']['javascript'], base_url() . JS . 'jquery.dataTables/jquery.dataTables.min.js');
					array_push($aData['_head']['javascript'], base_url() . JS . 'jquery.dataTables/jquery.dataTables.reloadAjax.js');
					
					$aData['_nav'] = array(
						'nav' => array(
							array(
							    'link' => base_url() . 'comandas',
							    'icone' => 'icon-moneybag', 
							    'nome' => 'Caixa', 
							    'subNav' => '', 
							    'subSubNav' => ''
					  		),
							array(
							    'link' => base_url() . 'pedidos/cozinha',
							    'icone' => 'icon-chef', 
							    'nome' => 'Cozinha', 
							    'subNav' => '', 
							    'subSubNav' => ''
					  		),
							array(
								'link' => base_url() . 'pedidos/bar',
								'icone' => 'icon-glass', 
								'nome' => 'Bar', 
								'subNav' => '', 
								'subSubNav' => ''
					  		),
							array(
								'link' => '#',
								'icone' => 'icon-settingsthree-gears',
								'nome' => 'Administração',
								'subNav' => array(
									array(
										'link' => base_url() . 'ambientes',
										'icone' => 'icon-th-large', 
										'nome' => 'Ambientes', 
										'subNav' => '' 
// 										'subSubNav' => array(
// 											'link' => 'ambientes/#criar',
// 											'icone' => 'icon-plus verde', 
// 											'nome' => 'Criar', 
// 											'subNav' => '', 
// 											'subSubNav' => ''
// 										)
									),
									array(
										'link' => base_url() . 'produtos',
										'icone' => 'icon-foodtray', 
										'nome' => 'Produtos', 
										'subNav' => ''
// 										'subSubNav' => array(
// 											'link' => base_url() . 'produtos/#criar',
// 											'icone' => 'icon-plus verde', 
// 											'nome' => 'Criar', 
// 											'subNav' => '', 
// 											'subSubNav' => ''
// 										)
									),
									array(
										'link' => base_url() . 'categorias',
										'icone' => 'icon-restaurantmenu', 
										'nome' => 'Categorias', 
										'subNav' => ''
// 										'subSubNav' => array(
// 											'link' => base_url() . 'categorias/#criar',
// 											'icone' => 'icon-plus verde', 
// 											'nome' => 'Criar', 
// 											'subNav' => '', 
// 											'subSubNav' => ''
// 										)
									),
									array(
										'link' => base_url() . 'usuarios',
										'icone' => 'icon-groups-friends', 
										'nome' => 'Usuários', 
										'subNav' => ''
// 										'subSubNav' => array(
// 											'link' => '#form_usuario',
// 											'icone' => 'icon-plus verde', 
// 											'nome' => 'Criar', 
// 											'subNav' => '', 
// 											'subSubNav' => ''
// 										)
									)
								),
							),
						)
					);

					$aData['_header'] = array(
						'usuario' => $this->session->userdata('login_usuario'),
						'icone' => 'icon-settingsthree-gears'
					);
					
					break;
					
				case 'caixa':
					
					array_push($aData['_head']['stylesheet'], base_url() . CSS . 'jquery.dataTables/jquery.dataTables.css');
					array_push($aData['_head']['javascript'], base_url() . JS . 'jquery.dataTables/jquery.dataTables.min.js');

					$aData['_nav'] = array(
						'nav' => array(
							array(
								'link' => '#',
								'icone' => 'icon-moneybag',
								'nome' => 'Caixa',
								'subNav' => '',
								'subSubNav' => ''
							)
						)
					);
					
					$aData['_header'] = array(
							'usuario' => $this->session->userdata('login_usuario'),
							'icone' => 'icon-moneybag'
					);
					
					break;
				case 'cozinha':
					
					array_push($aData['_head']['stylesheet'], base_url() . CSS . 'jquery.dataTables/jquery.dataTables.css');
					array_push($aData['_head']['javascript'], base_url() . JS . 'jquery.dataTables/jquery.dataTables.min.js');
						
					$aData['_nav'] = array(
						'nav' => array(
							array(
								'link' => '#',
								'icone' => 'icon-chef',
								'nome' => 'Cozinha',
								'subNav' => '',
								'subSubNav' => ''
							)
						)
					);
					
					$aData['_header'] = array(
							'usuario' => $this->session->userdata('login_usuario'),
							'icone' => 'icon-chef'
					);		
					
					break;
				case 'bar':
					
					array_push($aData['_head']['stylesheet'], base_url() . CSS . 'jquery.dataTables/jquery.dataTables.css');
					array_push($aData['_head']['javascript'], base_url() . JS . 'jquery.dataTables/jquery.dataTables.min.js');
						
					$aData['_nav'] = array(
						'nav' => array(
							array(
								'link' => '#',
								'icone' => 'icon-glass',
								'nome' => 'Bar',
								'subNav' => '',
								'subSubNav' => ''
							)
						)
					);
					
					$aData['_header'] = array(
						'usuario' => $this->session->userdata('login_usuario'),
						'icone' => 'icon-glass'
					);		
					
					break;
				default:
					show_404();
					break;
			}	
				$this->montarLayout($sView, $aData);
		}
	}
	
	private function montarLayout($sView, $aData){
		
		if($this->logado() == FALSE){
			
			$this->load->view('head', $aData['_head']);
			$this->load->view($sView, $aData);
			
		} else {
			
			$this->load->view('head', $aData['_head']);		
			if(isset($aData['_header'])){ 
				$this->load->view('header', $aData['_header']);
			}
			if(isset($aData['_header'])){ 
				$this->load->view('nav', $aData['_nav']);
			}
			$this->load->view($sView, $aData);
			if(isset($aData['_header'])){
				$this->load->view('footer', $aData['_footer']);
			}
			
		}
	}
}

/* End of file Index.php */